package controllers.managers
{
	import mx.core.UIComponent;
	
	import ui20131001.AnnouncementPanel;
	import ui20131001.DeviceInfoPanel;
	import ui20131001.DeviceListWindow;
	import ui20131001.DeviceMenuPanel;
	import ui20131001.FeedbackWin;
	import ui20131001.HistoryListWindow;
	
	import view.ListPanel;
	import view.LoginPanel;
	import view.MapCanvas;
	import view.mediator.LoginMediator;
	import view.mediator.multidevs.DeviceSelectionMediator;
	import view.mediator.multidevs.MultiDeviceMonitorMediator;
	import view.panel.DeviceSelectionPanel;
	import view.panel.MultiDeviceMonitor;

	public class UIInstanceManager
	{
		public static var NAME : String = "UIInstanceManager";
		private var map:Object = new Object();
		private static var inst:UIInstanceManager;
		
		public function UIInstanceManager()
		{
		}
		
		/**
		 * 获取实例
		 **/
		public static function getInst():UIInstanceManager 
		{
			if ( inst == null )
			{
				inst = new UIInstanceManager();
			}
			return inst;
		}
		
		public static function initUIMgr(mainApp:Maper):void
		{
			getInst().initView(mainApp);
		}
		
		public function initView(mainApp:Maper):void {
			
			registerMediators(mainApp);
			//注册ListPanel
			register(Maper.NAME, mainApp);
			register(LoginPanel.NAME, mainApp.loginPanel);
			register(ListPanel.NAME, mainApp.listPanel);
			register(DeviceSelectionPanel.NAME, mainApp.panelDeviceSelection);
			register(MultiDeviceMonitor.NAME, mainApp.panelMultiDeviceMonitor);
			register(MapCanvas.NAME, mainApp.mapCanvas);
			register(DeviceListWindow.NAME, mainApp.deviceListWindow);
			register(DeviceInfoPanel.NAME, mainApp.deviceInfoPanel);
			register(HistoryListWindow.NAME, mainApp.historyListWindow);
			register(AnnouncementPanel.NAME, mainApp.announcementPanel);
			register(FeedbackWin.NAME, mainApp.feedbackWin);
		}
		
		private function registerMediators(mainApp:Maper):void
		{
			//注册Mediator
			new DeviceSelectionMediator().setView(mainApp.panelDeviceSelection);
			new MultiDeviceMonitorMediator().setView(mainApp.panelMultiDeviceMonitor);
			new LoginMediator().setView(mainApp.loginPanel);
		}
		
		/**
		 * 注册UI
		 **/
		public static function register(name:String, value:UIComponent):void
		{
			getInst().setView(name, value);
		}
		
		public static function getUI(name:String):UIComponent
		{
			return getInst().getView(name);
		}
		
		public function setView(name:String, ui:UIComponent):void
		{
			map[name] = ui;
		}
		
		public function getView(name:String):UIComponent
		{
			return UIComponent(map[name]);
		}
	}
}